package com.easemob.chatuidemo.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;
import com.easemob.chatuidemo.R;

import com.easemob.chatuidemo.activity.SettingActivity;
import com.easemob.chatuidemo.activity.UserProfileActivity;

import com.easemob.chatuidemo.scanning.CaptureActivity;
import com.easemob.chatuidemo.utils.UserUtils;
import com.easemob.chatuidemo.widget.CircleImageView;
import com.easemob.skin.SkinActivity;


/**
 * Created by lanou3g on 15/9/16.
 */
public class PersonalFragment extends Fragment implements View.OnClickListener {
    private CircleImageView circleImageView;
    private Button buttonSetting, buttonSetTheme, buttonScan;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.personalfragment, container, false);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initWight();
        if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false))
            return;
    }

    private void initWight() {
        buttonScan = (Button) getActivity().findViewById(R.id.button_scan);

        buttonSetTheme = (Button) getActivity().findViewById(R.id.button_set_theme);

        buttonSetting = (Button) getActivity().findViewById(R.id.button_setting);

        buttonSetting.setOnClickListener(this);
        buttonSetTheme.setOnClickListener(this);
        buttonScan.setOnClickListener(this);

        circleImageView = (CircleImageView) getActivity().findViewById(R.id.circle_image);


        // 设置头像到该控件里.
        UserUtils.setCurrentUserAvatar(getActivity(), circleImageView);

        // 设置监听
        circleImageView.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){

            case R.id.circle_image:
                startActivity(new Intent(getActivity(), UserProfileActivity.class).putExtra("setting", true));
                break;

            case R.id.button_setting:

                startActivity(new Intent(getActivity(),SettingActivity.class));
                break;
            case R.id.button_set_theme:

                startActivity(new Intent(getActivity(),SkinActivity.class));
                break;
            case R.id.button_scan:

                startActivity(new Intent(getActivity(),CaptureActivity.class));
                break;
            default:
                Toast.makeText(getActivity(), "Error", Toast.LENGTH_SHORT).show();
                break;
        }

    }
}